package part11;

import java.util.*;

/**
 * @author wcj
 * @Date 2021/5/20 18:29
 * @Version 1.0
 */
public class Part1113 {

    public static void display(Iterator<Integer> iterator) {
        while (iterator.hasNext()) {
            Integer next = iterator.next();
            System.out.println("next=" + next);
        }
    }

    public static void display(Collection<Integer> collection) {
        for (Integer i : collection) {
            System.out.println(i);
        }
    }


    public static void main(String[] args) {
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6);
        Set<Integer> set = new HashSet<>(list);
        Map<String, Integer> map = new HashMap<>();
        String[] names = ("wcj,hhy,bss," + "ysj,ylb,ljh").split(",");
        for (int i = 0; i < names.length; i++) {
            map.put(names[i], list.get(i));
        }
        display(list);
        display(set);
        display(list.iterator());
        display(set.iterator());
        System.out.println(map);
        System.out.println(map.keySet());
        display(map.values());
        display(map.values().iterator());
    }
}

/**
 * Collection和迭代器绑定到了一块，实现Collection，就必须要去实现迭代器
 */
class CollectionSequence extends AbstractCollection<Integer> {

    @Override
    public Iterator<Integer> iterator() {
        return null;
    }

    @Override
    public int size() {
        return 0;
    }
}
